﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PaperManager
{
    public partial class MainForm : Form
    {
        public MyContainer paperAL;
        public MainForm()
        {
            InitializeComponent();
            //初始化数据列
            DataGridViewTextBoxColumn colTitle = new DataGridViewTextBoxColumn();
            colTitle.HeaderText = "论文名";
            grdPaper.Columns.Add(colTitle);
            DataGridViewTextBoxColumn colAuthor = new DataGridViewTextBoxColumn();
            colAuthor.HeaderText = "作者";
            grdPaper.Columns.Add(colAuthor);
            DataGridViewTextBoxColumn colKeyWords = new DataGridViewTextBoxColumn();
            colKeyWords.HeaderText = "关键词";
            grdPaper.Columns.Add(colKeyWords);
            DataGridViewTextBoxColumn colAbstract = new DataGridViewTextBoxColumn();
            colAbstract.HeaderText = "摘要";
            grdPaper.Columns.Add(colAbstract);
            //初始化变量
            paperAL = new MyDBContainer("D:\\HomeWork\\PaperManager\\PaperManager\\data\\PaperManagerDB.mdb");
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            AddForm addForm = new AddForm();
            addForm.paForm = this;
            addForm.mode = true;
            addForm.ShowDialog();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            grdPaper.Rows.Remove(grdPaper.CurrentRow);
            paperAL.remove(grdPaper.CurrentRow.Index);
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            AddForm modifyForm = new AddForm();
            modifyForm.paForm = this;
            modifyForm.mode = false;
            modifyForm.Text = "修改论文";
            //取出被修改的内容,gridview与arraylist的索引一致,从arraylist中取数据
            int idx = this.grdPaper.CurrentRow.Index;            
            modifyForm.tbxTitle.Text = paperAL.get(idx).Title;
            modifyForm.tbxAuthor.Text = paperAL.get(idx).Author;
            modifyForm.tbxKeyWords.Text = paperAL.get(idx).KeyWords;
            modifyForm.tbxAbstract.Text = paperAL.get(idx).Abstract;
            modifyForm.ShowDialog();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            QueryForm queryForm = new QueryForm();
            queryForm.paForm = this;
            queryForm.ShowDialog();
        }
    }
}
